package com.ylsd.prospectivestudent.service.impl;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.C;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ylsd.prospectivestudent.entity.*;
import com.ylsd.prospectivestudent.mapper.PSMapper;
import com.ylsd.prospectivestudent.service.PSService;
import org.springframework.stereotype.Service;
import org.ylsdxy.model.response.CustomPage;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PSServiceImpl implements PSService {
    @Resource
    private PSMapper psMapper;
    @Override
    public CustomPage<List<ProspectiveStudent>> findByPage(ProspectiveStudent prospectiveStudent) {
        if (prospectiveStudent.getTime() != null ){
            prospectiveStudent.setStartTime(prospectiveStudent.getTime().get(0));
            prospectiveStudent.setEndTime(prospectiveStudent.getTime().get(1));
        }
        PageHelper.startPage(prospectiveStudent.getPage(), prospectiveStudent.getSize());
        List<ProspectiveStudent> list = psMapper.findByPage(prospectiveStudent);
        PageInfo<ProspectiveStudent> pageInfo = new PageInfo<>(list);

        CustomPage<List<ProspectiveStudent>> customPage = CustomPage.<List<ProspectiveStudent>>builder()
                .currentPage(prospectiveStudent.getPage())
                .size(prospectiveStudent.getSize())
                .totalPage(pageInfo.getPages())
                .total(pageInfo.getTotal())
                .data(list)
                .build();
        return customPage;
    }

    @Override
    public boolean insertPS(ProspectiveStudent student) {
        return psMapper.insertPS(student);
    }

    @Override
    public boolean delPS(List<Integer> id) {
        return psMapper.delPS(id);
    }

    @Override
    public boolean updatePS(ProspectiveStudent student) {
        return psMapper.updatePS(student);
    }

    @Override
    public CustomPage<List<ProspectiveStudent>> findByDelPage(ProspectiveStudent prospectiveStudent) {
        PageHelper.startPage(prospectiveStudent.getPage(), prospectiveStudent.getSize());
        List<ProspectiveStudent> list = psMapper.findByDelPage(prospectiveStudent);
        PageInfo<ProspectiveStudent> pageInfo = new PageInfo<>(list);

        CustomPage<List<ProspectiveStudent>> customPage = CustomPage.<List<ProspectiveStudent>>builder()
                .currentPage(prospectiveStudent.getPage())
                .size(prospectiveStudent.getSize())
                .totalPage(pageInfo.getPages())
                .total(pageInfo.getTotal())
                .data(list)
                .build();
        return customPage;
    }

    @Override
    public List<StudentSource> findBySource() {
        return psMapper.findBySource();
    }

    @Override
    public List<Teacher> findByTeacher() {
        return psMapper.findByTeacher();
    }

    @Override
    public ProspectiveStudent findByCid(Integer cid) {
        return psMapper.findByCid(cid);
    }

    @Override
    public ProspectiveStudent findDelDetailById(Integer id) {
        return psMapper.findDelDetailById(id);
    }

    @Override
    public List<PSExcel> findByExcel() {
        return psMapper.findByExcel();
    }

    @Override
    public List<PSExcelModel> findByExcelModel() {
        return psMapper.findByExcelModel();
    }

    @Override
    public void importStudents(List<ImportStudents> studentList) {
       psMapper.importStudents(studentList);
    }

    @Override
    public List<CountGroup> findCountGroupByDate() {
        return psMapper.findCountGroupByDate();
    }

    @Override
    public List<PSPie> findPie() {
        return psMapper.findPie();
    }

    @Override
    public Integer piecount() {
        return psMapper.piecount();
    }

    @Override
    public Integer newStudent() {
        return psMapper.newStudent();
    }

    @Override
    public Integer delStudent() {
        return psMapper.delStudent();
    }


}
